const query = require("../db/query");
var md5 = require("md5");
// id查找语句 
const findId = async (ctx) => {
  const sql = `select * from login where id='${ctx.id}'`;
  return await query(sql);
};
const login = async (ctx) => {
  //登录语句
  const sql = `select * from login where phone='${ctx.phone}' and password='${md5(ctx.password)}'`;
  return await query(sql);
};
// 注册
const register = async (ctx) => {
  const sql = `insert into login  (phone,password) values ('${ctx.phone}','${md5(ctx.password)}')`;
  return await query(sql);
};
// 验证码登录
const verificationcode = async (ctx) => {
  const sql = ` select * from login where phone='${ctx.phone1}' `;
  return await query(sql);
};
//  修改密码
const updatepassword = async (ctx) => {
  const sql = `UPDATE login SET password = '${md5(ctx.password)}' WHERE id ='${ctx.id}';`;
  return await query(sql);
};
// 修改名字 
const updateName = async (ctx) => {
  const sql = `UPDATE login SET name = '${ctx.name}'  WHERE id = '${ctx.id}';`;
  return await query(sql);
};
// 修改图片 
const updateImg = async (ctx) => {
  const sql = `UPDATE login SET img = '${ctx.img}'  WHERE id = '${ctx.id}';`;
  return await query(sql);
};
//  首页所有列表数据
const homeall = async (ctx) => {
  const sql = `SELECT * FROM homeall;`;
  return await query(sql);
};
// 订单
const orderform = async (ctx) => {
  const sql = `SELECT * FROM orderform`;
  return await query(sql);
};

//  分类
const classification = async (ctx) => {
  const sql = `SELECT * FROM homeclassification;`;
  return await query(sql);
};

// 查找详情 id
const addDetails = async (ctx) => {
  const sql = `SELECT * FROM homeall  where id = '${ctx.id}'`;
  return await query(sql);
}

module.exports = {
  homeall,
  login,
  orderform,
  register,
  verificationcode,
  classification,
  updatepassword,
  updateName,
  findId,
  updateImg,
  addDetails
};